package model;

import java.sql.*;
import java.util.Date;
import dal.*;
import util.*;

public class PersonModel implements IModel {

	public static class FieldNames {
		public static String Id = "Id";
		public static String IsEmployee = "IsEmployee";
		public static String FirstName = "FirstName";
		public static String LastName = "LastName";
		public static String Mobile = "Mobile";
		public static String CompanyPhone = "CompanyPhone";
		public static String HomePhone = "HomePhone";
		public static String CompanyEmail = "CompanyEmail";
		public static String PersonalEmail = "PersonalEmail";
		public static String Address = "Address";
		public static String Birthdate = "Birthdate";
		public static String IdentityNo = "IdentityNo";
		public static String Gender = "Gender";
		public static String Description = "Description";
		public static String Status = "Status";
		public static String IsDraft = "IsDraft";
		public static String Notification = "Notification";
		public static String Created = "Created";
		public static String Creator = "Creator";
		public static String Updated = "Updated";
		public static String Updator = "Updator";
		public static String Deleted = "Deleted";
		public static String DeletionTime = "DeletionTime";
		public static String MiddleName = "MiddleName";
		public static String IdEmployee = "IdEmployee";
	
	}

	public class ErrorMessages {
		public String Id = "";
		public String IsEmployee = "";
		public String FirstName = "";
		public String LastName = "";
		public String Mobile = "";
		public String CompanyPhone = "";
		public String HomePhone = "";
		public String CompanyEmail = "";
		public String PersonalEmail = "";
		public String Address = "";
		public String Birthdate = "";
		public String IdentityNo = "";
		public String Gender = "";
		public String Description = "";
		public String Status = "";
		public String IsDraft = "";
		public String Notification = "";
		public String Created = "";
		public String Creator = "";
		public String Updated = "";
		public String Updator = "";
		public String Deleted = "";
		public String DeletionTime = "";
		public String MiddleName = "";
		public String IdEmployee = "";
	
	}

    public ErrorMessages errMsgs = new ErrorMessages();

	public String[] errMsgList = null;

// private variables
private int _id = Integer.MIN_VALUE;
private boolean _is_employee = false;
private boolean _isis_employeeSet = false;
private String _first_name = null;
private String _last_name = null;
private String _mobile = null;
private String _company_phone = null;
private String _home_phone = null;
private String _company_email = null;
private String _personal_email = null;
private String _address = null;
private Date _birthdate = null;
private String _identity_no = null;
private boolean _gender = false;
private boolean _isgenderSet = false;
private String _description = null;
private int _status = Integer.MIN_VALUE;
private boolean _is_draft = false;
private boolean _isis_draftSet = false;
private int _notification = Integer.MIN_VALUE;
private Date _created = null;
private int _creator = Integer.MIN_VALUE;
private Date _updated = null;
private int _updator = Integer.MIN_VALUE;
private boolean _deleted = false;
private boolean _isdeletedSet = false;
private Date _deletion_time = null;
private String _middle_name = null;
private int _id_employee = Integer.MIN_VALUE;


	public PersonModel() {
	}

// get/set
public int getId() {
		return _id;
	}
public void setId(int value) {
		_id = value;
	}
public String getIdToString() {
		if (_id == Integer.MIN_VALUE
				|| _id == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id);
		}
	}
public boolean getIsEmployee() {
		return _is_employee;
	}
public void setIsEmployee(boolean value) {
		_is_employee = value;
		_isis_employeeSet = true;
	}
public boolean getIsEmployeeSet() {
		return _isis_employeeSet;
	}
	public String getIsEmployeeToString() {
		if (_isis_employeeSet) {
			return HtmlUtil.genHtml(_is_employee);
		} else {
			return "";
		}
	}
public String getFirstName() {
		return _first_name;
	}
public void setFirstName(String value) {
		_first_name = value;
	}
public String getFirstNameToString() {
		if (_first_name != null) {
			return HtmlUtil.genHtml(_first_name);
		} else {
			return "";
		}
	}
public String getLastName() {
		return _last_name;
	}
public void setLastName(String value) {
		_last_name = value;
	}
public String getLastNameToString() {
		if (_last_name != null) {
			return HtmlUtil.genHtml(_last_name);
		} else {
			return "";
		}
	}
public String getMobile() {
		return _mobile;
	}
public void setMobile(String value) {
		_mobile = value;
	}
public String getMobileToString() {
		if (_mobile != null) {
			return HtmlUtil.genHtml(_mobile);
		} else {
			return "";
		}
	}
public String getCompanyPhone() {
		return _company_phone;
	}
public void setCompanyPhone(String value) {
		_company_phone = value;
	}
public String getCompanyPhoneToString() {
		if (_company_phone != null) {
			return HtmlUtil.genHtml(_company_phone);
		} else {
			return "";
		}
	}
public String getHomePhone() {
		return _home_phone;
	}
public void setHomePhone(String value) {
		_home_phone = value;
	}
public String getHomePhoneToString() {
		if (_home_phone != null) {
			return HtmlUtil.genHtml(_home_phone);
		} else {
			return "";
		}
	}
public String getCompanyEmail() {
		return _company_email;
	}
public void setCompanyEmail(String value) {
		_company_email = value;
	}
public String getCompanyEmailToString() {
		if (_company_email != null) {
			return HtmlUtil.genHtml(_company_email);
		} else {
			return "";
		}
	}
public String getPersonalEmail() {
		return _personal_email;
	}
public void setPersonalEmail(String value) {
		_personal_email = value;
	}
public String getPersonalEmailToString() {
		if (_personal_email != null) {
			return HtmlUtil.genHtml(_personal_email);
		} else {
			return "";
		}
	}
public String getAddress() {
		return _address;
	}
public void setAddress(String value) {
		_address = value;
	}
public String getAddressToString() {
		if (_address != null) {
			return HtmlUtil.genHtml(_address);
		} else {
			return "";
		}
	}
public Date getBirthdate() {
		return _birthdate;
	}
public void setBirthdate(Date value) {
		_birthdate = value;
	}
public String getBirthdateToString() {
		if (_birthdate != null) {
			return StringUtil.toDateTimeString(_birthdate);
		} else {
			return "";
		}
	}
public String getIdentityNo() {
		return _identity_no;
	}
public void setIdentityNo(String value) {
		_identity_no = value;
	}
public String getIdentityNoToString() {
		if (_identity_no != null) {
			return HtmlUtil.genHtml(_identity_no);
		} else {
			return "";
		}
	}
public boolean getGender() {
		return _gender;
	}
public void setGender(boolean value) {
		_gender = value;
		_isgenderSet = true;
	}
public boolean getGenderSet() {
		return _isgenderSet;
	}
	public String getGenderToString() {
		if (_isgenderSet) {
			return HtmlUtil.genHtml(_gender);
		} else {
			return "";
		}
	}
public String getDescription() {
		return _description;
	}
public void setDescription(String value) {
		_description = value;
	}
public String getDescriptionToString() {
		if (_description != null) {
			return HtmlUtil.genHtml(_description);
		} else {
			return "";
		}
	}
public int getStatus() {
		return _status;
	}
public void setStatus(int value) {
		_status = value;
	}
public String getStatusToString() {
		if (_status == Integer.MIN_VALUE
				|| _status == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_status);
		}
	}
public boolean getIsDraft() {
		return _is_draft;
	}
public void setIsDraft(boolean value) {
		_is_draft = value;
		_isis_draftSet = true;
	}
public boolean getIsDraftSet() {
		return _isis_draftSet;
	}
	public String getIsDraftToString() {
		if (_isis_draftSet) {
			return HtmlUtil.genHtml(_is_draft);
		} else {
			return "";
		}
	}
public int getNotification() {
		return _notification;
	}
public void setNotification(int value) {
		_notification = value;
	}
public String getNotificationToString() {
		if (_notification == Integer.MIN_VALUE
				|| _notification == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_notification);
		}
	}
public Date getCreated() {
		return _created;
	}
public void setCreated(Date value) {
		_created = value;
	}
public String getCreatedToString() {
		if (_created != null) {
			return StringUtil.toDateTimeString(_created);
		} else {
			return "";
		}
	}
public int getCreator() {
		return _creator;
	}
public void setCreator(int value) {
		_creator = value;
	}
public String getCreatorToString() {
		if (_creator == Integer.MIN_VALUE
				|| _creator == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_creator);
		}
	}
public Date getUpdated() {
		return _updated;
	}
public void setUpdated(Date value) {
		_updated = value;
	}
public String getUpdatedToString() {
		if (_updated != null) {
			return StringUtil.toDateTimeString(_updated);
		} else {
			return "";
		}
	}
public int getUpdator() {
		return _updator;
	}
public void setUpdator(int value) {
		_updator = value;
	}
public String getUpdatorToString() {
		if (_updator == Integer.MIN_VALUE
				|| _updator == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_updator);
		}
	}
public boolean getDeleted() {
		return _deleted;
	}
public void setDeleted(boolean value) {
		_deleted = value;
		_isdeletedSet = true;
	}
public boolean getDeletedSet() {
		return _isdeletedSet;
	}
	public String getDeletedToString() {
		if (_isdeletedSet) {
			return HtmlUtil.genHtml(_deleted);
		} else {
			return "";
		}
	}
public Date getDeletionTime() {
		return _deletion_time;
	}
public void setDeletionTime(Date value) {
		_deletion_time = value;
	}
public String getDeletionTimeToString() {
		if (_deletion_time != null) {
			return StringUtil.toDateTimeString(_deletion_time);
		} else {
			return "";
		}
	}
public String getMiddleName() {
		return _middle_name;
	}
public void setMiddleName(String value) {
		_middle_name = value;
	}
public String getMiddleNameToString() {
		if (_middle_name != null) {
			return HtmlUtil.genHtml(_middle_name);
		} else {
			return "";
		}
	}
public int getIdEmployee() {
		return _id_employee;
	}
public void setIdEmployee(int value) {
		_id_employee = value;
	}
public String getIdEmployeeToString() {
		if (_id_employee == Integer.MIN_VALUE
				|| _id_employee == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_employee);
		}
	}

//implement methods
public String getName() {
	return _first_name;
}

	@Override
	public int[] getPrimaryKey() {
		int[] ids = new int[1];
		ids[0] = getId();
		return ids;
	}

	@Override
	public IModel readFromResultSet(ResultSet rs) throws SQLException {
		PersonModel model = null;

			model = new PersonModel();

// read fields
{
				int value = rs.getInt("id");
				if (!rs.wasNull()) {
					model.setId(value);
				}
			}
{
				boolean value = rs.getBoolean("is_employee");
				if (!rs.wasNull()) {
					model.setIsEmployee(value);
				}
			}
{
				String value = rs.getString("first_name");
				if (!rs.wasNull()) {
					model.setFirstName(value);
				}
			}
{
				String value = rs.getString("last_name");
				if (!rs.wasNull()) {
					model.setLastName(value);
				}
			}
{
				String value = rs.getString("mobile");
				if (!rs.wasNull()) {
					model.setMobile(value);
				}
			}
{
				String value = rs.getString("company_phone");
				if (!rs.wasNull()) {
					model.setCompanyPhone(value);
				}
			}
{
				String value = rs.getString("home_phone");
				if (!rs.wasNull()) {
					model.setHomePhone(value);
				}
			}
{
				String value = rs.getString("company_email");
				if (!rs.wasNull()) {
					model.setCompanyEmail(value);
				}
			}
{
				String value = rs.getString("personal_email");
				if (!rs.wasNull()) {
					model.setPersonalEmail(value);
				}
			}
{
				String value = rs.getString("address");
				if (!rs.wasNull()) {
					model.setAddress(value);
				}
			}
{
				Date value = rs.getTimestamp("birthdate");
				if (!rs.wasNull()) {
					model.setBirthdate(value);
				}
			}
{
				String value = rs.getString("identity_no");
				if (!rs.wasNull()) {
					model.setIdentityNo(value);
				}
			}
{
				boolean value = rs.getBoolean("gender");
				if (!rs.wasNull()) {
					model.setGender(value);
				}
			}
{
				String value = rs.getString("description");
				if (!rs.wasNull()) {
					model.setDescription(value);
				}
			}
{
				int value = rs.getInt("status");
				if (!rs.wasNull()) {
					model.setStatus(value);
				}
			}
{
				boolean value = rs.getBoolean("is_draft");
				if (!rs.wasNull()) {
					model.setIsDraft(value);
				}
			}
{
				int value = rs.getInt("notification");
				if (!rs.wasNull()) {
					model.setNotification(value);
				}
			}
{
				Date value = rs.getTimestamp("created");
				if (!rs.wasNull()) {
					model.setCreated(value);
				}
			}
{
				int value = rs.getInt("creator");
				if (!rs.wasNull()) {
					model.setCreator(value);
				}
			}
{
				Date value = rs.getTimestamp("updated");
				if (!rs.wasNull()) {
					model.setUpdated(value);
				}
			}
{
				int value = rs.getInt("updator");
				if (!rs.wasNull()) {
					model.setUpdator(value);
				}
			}
{
				boolean value = rs.getBoolean("deleted");
				if (!rs.wasNull()) {
					model.setDeleted(value);
				}
			}
{
				Date value = rs.getTimestamp("deletion_time");
				if (!rs.wasNull()) {
					model.setDeletionTime(value);
				}
			}
{
				String value = rs.getString("middle_name");
				if (!rs.wasNull()) {
					model.setMiddleName(value);
				}
			}
{
				int value = rs.getInt("id_employee");
				if (!rs.wasNull()) {
					model.setIdEmployee(value);
				}
			}
		

		return model;
	}

	@Override
	public PreparedStatement genSelectStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "SELECT * FROM sp_person_select(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

        PersonModel obj = (PersonModel )query;
		
// set parameters
st.setObject("id", obj.getId());


		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genSelectListStatement(Connection dbConn,
			IModelExt query) throws SQLException {
		String sql = "SELECT * FROM sp_person_selectList(:limit, :offset, :id,:is_employee,:first_name,:last_name,:mobile,:company_phone,:home_phone,:company_email,:personal_email,:address,:birthdateFrom,:birthdateTo,:identity_no,:gender,:description,:status,:is_draft,:notification,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo,:middle_name,:id_employee)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		PersonModelExt obj = (PersonModelExt) query;

		if (obj.getLimit() != Integer.MIN_VALUE) {
			st.setObject("limit", obj.getLimit());
		}  else {
			st.setObject("limit", Integer.MAX_VALUE);
		}
		if (obj.getOffset() != Integer.MIN_VALUE) {
			st.setObject("offset", obj.getOffset());
		}  else {
			st.setObject("offset", 0);
		}

// set parameters
if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
            st.setObject("id", null);
}
		if (obj.getIsEmployeeSet()) {
			st.setObject("is_employee", obj.getIsEmployee());
		} else {
            st.setObject("is_employee", null);
}
if (obj.getFirstName() != null) {
			st.setObject("first_name", obj.getFirstName());
		} else {
            st.setObject("first_name", null);
}
if (obj.getLastName() != null) {
			st.setObject("last_name", obj.getLastName());
		} else {
            st.setObject("last_name", null);
}
if (obj.getMobile() != null) {
			st.setObject("mobile", obj.getMobile());
		} else {
            st.setObject("mobile", null);
}
if (obj.getCompanyPhone() != null) {
			st.setObject("company_phone", obj.getCompanyPhone());
		} else {
            st.setObject("company_phone", null);
}
if (obj.getHomePhone() != null) {
			st.setObject("home_phone", obj.getHomePhone());
		} else {
            st.setObject("home_phone", null);
}
if (obj.getCompanyEmail() != null) {
			st.setObject("company_email", obj.getCompanyEmail());
		} else {
            st.setObject("company_email", null);
}
if (obj.getPersonalEmail() != null) {
			st.setObject("personal_email", obj.getPersonalEmail());
		} else {
            st.setObject("personal_email", null);
}
if (obj.getAddress() != null) {
			st.setObject("address", obj.getAddress());
		} else {
            st.setObject("address", null);
}
if (obj.getBirthdateFrom() != null) {
			st.setObject("birthdateFrom", obj.getBirthdateFrom());
		} else {
			st.setObject("birthdateFrom", null);
		}
		if (obj.getBirthdateTo() != null) {
			st.setObject("birthdateTo", obj.getBirthdateTo());
		} else {
            st.setObject("birthdateTo", null);
}
if (obj.getIdentityNo() != null) {
			st.setObject("identity_no", obj.getIdentityNo());
		} else {
            st.setObject("identity_no", null);
}
		if (obj.getGenderSet()) {
			st.setObject("gender", obj.getGender());
		} else {
            st.setObject("gender", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
            st.setObject("description", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
            st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
            st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
            st.setObject("notification", null);
}
if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
            st.setObject("createdTo", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
            st.setObject("creator", null);
}
if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
            st.setObject("updatedTo", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
            st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
            st.setObject("deleted", null);
}
if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
            st.setObject("deletion_timeTo", null);
}
if (obj.getMiddleName() != null) {
			st.setObject("middle_name", obj.getMiddleName());
		} else {
            st.setObject("middle_name", null);
}
if (obj.getIdEmployee() != Integer.MIN_VALUE) {
			st.setObject("id_employee", obj.getIdEmployee());
		} else {
            st.setObject("id_employee", null);
}
	

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genInsertStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_person_insert(:is_employee,:first_name,:last_name,:mobile,:company_phone,:home_phone,:company_email,:personal_email,:address,:birthdate,:identity_no,:gender,:description,:status,:is_draft,:notification,:creator,:middle_name,:id_employee)";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		PersonModel obj = (PersonModel) model;

		// set parameters here
		if (obj.getIsEmployeeSet()) {
			st.setObject("is_employee", obj.getIsEmployee());
		} else {
			st.setObject("is_employee", null);
}
if (obj.getFirstName() != null) {
			st.setObject("first_name", obj.getFirstName());
		} else {
			st.setObject("first_name", null);
}
if (obj.getLastName() != null) {
			st.setObject("last_name", obj.getLastName());
		} else {
			st.setObject("last_name", null);
}
if (obj.getMobile() != null) {
			st.setObject("mobile", obj.getMobile());
		} else {
			st.setObject("mobile", null);
}
if (obj.getCompanyPhone() != null) {
			st.setObject("company_phone", obj.getCompanyPhone());
		} else {
			st.setObject("company_phone", null);
}
if (obj.getHomePhone() != null) {
			st.setObject("home_phone", obj.getHomePhone());
		} else {
			st.setObject("home_phone", null);
}
if (obj.getCompanyEmail() != null) {
			st.setObject("company_email", obj.getCompanyEmail());
		} else {
			st.setObject("company_email", null);
}
if (obj.getPersonalEmail() != null) {
			st.setObject("personal_email", obj.getPersonalEmail());
		} else {
			st.setObject("personal_email", null);
}
if (obj.getAddress() != null) {
			st.setObject("address", obj.getAddress());
		} else {
			st.setObject("address", null);
}
if (obj.getBirthdate() != null) {
			st.setObject("birthdate", obj.getBirthdate());
		} else {
			st.setObject("birthdate", null);
}
if (obj.getIdentityNo() != null) {
			st.setObject("identity_no", obj.getIdentityNo());
		} else {
			st.setObject("identity_no", null);
}
		if (obj.getGenderSet()) {
			st.setObject("gender", obj.getGender());
		} else {
			st.setObject("gender", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
			st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
			st.setObject("notification", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
			st.setObject("creator", null);
}
if (obj.getMiddleName() != null) {
			st.setObject("middle_name", obj.getMiddleName());
		} else {
			st.setObject("middle_name", null);
}
if (obj.getIdEmployee() != Integer.MIN_VALUE) {
			st.setObject("id_employee", obj.getIdEmployee());
		} else {
			st.setObject("id_employee", null);
}
	

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genUpdateStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_person_update(:id,:is_employee,:first_name,:last_name,:mobile,:company_phone,:home_phone,:company_email,:personal_email,:address,:birthdate,:identity_no,:gender,:description,:status,:is_draft,:notification,:updator,:deleted,:deletion_time,:middle_name,:id_employee)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		PersonModel obj = (PersonModel) model;

		// set parameters here
if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
			st.setObject("id", null);
}
		if (obj.getIsEmployeeSet()) {
			st.setObject("is_employee", obj.getIsEmployee());
		} else {
			st.setObject("is_employee", null);
}
if (obj.getFirstName() != null) {
			st.setObject("first_name", obj.getFirstName());
		} else {
			st.setObject("first_name", null);
}
if (obj.getLastName() != null) {
			st.setObject("last_name", obj.getLastName());
		} else {
			st.setObject("last_name", null);
}
if (obj.getMobile() != null) {
			st.setObject("mobile", obj.getMobile());
		} else {
			st.setObject("mobile", null);
}
if (obj.getCompanyPhone() != null) {
			st.setObject("company_phone", obj.getCompanyPhone());
		} else {
			st.setObject("company_phone", null);
}
if (obj.getHomePhone() != null) {
			st.setObject("home_phone", obj.getHomePhone());
		} else {
			st.setObject("home_phone", null);
}
if (obj.getCompanyEmail() != null) {
			st.setObject("company_email", obj.getCompanyEmail());
		} else {
			st.setObject("company_email", null);
}
if (obj.getPersonalEmail() != null) {
			st.setObject("personal_email", obj.getPersonalEmail());
		} else {
			st.setObject("personal_email", null);
}
if (obj.getAddress() != null) {
			st.setObject("address", obj.getAddress());
		} else {
			st.setObject("address", null);
}
if (obj.getBirthdate() != null) {
			st.setObject("birthdate", obj.getBirthdate());
		} else {
			st.setObject("birthdate", null);
}
if (obj.getIdentityNo() != null) {
			st.setObject("identity_no", obj.getIdentityNo());
		} else {
			st.setObject("identity_no", null);
}
		if (obj.getGenderSet()) {
			st.setObject("gender", obj.getGender());
		} else {
			st.setObject("gender", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
			st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
			st.setObject("notification", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
			st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
			st.setObject("deleted", null);
}
if (obj.getDeletionTime() != null) {
			st.setObject("deletion_time", obj.getDeletionTime());
		} else {
			st.setObject("deletion_time", null);
}
if (obj.getMiddleName() != null) {
			st.setObject("middle_name", obj.getMiddleName());
		} else {
			st.setObject("middle_name", null);
}
if (obj.getIdEmployee() != Integer.MIN_VALUE) {
			st.setObject("id_employee", obj.getIdEmployee());
		} else {
			st.setObject("id_employee", null);
}

	
		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genDeleteStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "select sp_person_delete(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

        PersonModel obj = (PersonModel) query;

		// set primary keys
st.setObject("id", obj.getId());


		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genCountStatement(Connection dbConn,
			IModelExt input) throws SQLException {
		String sql = "SELECT sp_person_count(:id,:is_employee,:first_name,:last_name,:mobile,:company_phone,:home_phone,:company_email,:personal_email,:address,:birthdateFrom,:birthdateTo,:identity_no,:gender,:description,:status,:is_draft,:notification,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo,:middle_name,:id_employee)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		PersonModelExt obj = (PersonModelExt) input;

		// set parameters here
if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
            st.setObject("id", null);
}
		if (obj.getIsEmployeeSet()) {
			st.setObject("is_employee", obj.getIsEmployee());
		} else {
            st.setObject("is_employee", null);
}
if (obj.getFirstName() != null) {
			st.setObject("first_name", obj.getFirstName());
		} else {
            st.setObject("first_name", null);
}
if (obj.getLastName() != null) {
			st.setObject("last_name", obj.getLastName());
		} else {
            st.setObject("last_name", null);
}
if (obj.getMobile() != null) {
			st.setObject("mobile", obj.getMobile());
		} else {
            st.setObject("mobile", null);
}
if (obj.getCompanyPhone() != null) {
			st.setObject("company_phone", obj.getCompanyPhone());
		} else {
            st.setObject("company_phone", null);
}
if (obj.getHomePhone() != null) {
			st.setObject("home_phone", obj.getHomePhone());
		} else {
            st.setObject("home_phone", null);
}
if (obj.getCompanyEmail() != null) {
			st.setObject("company_email", obj.getCompanyEmail());
		} else {
            st.setObject("company_email", null);
}
if (obj.getPersonalEmail() != null) {
			st.setObject("personal_email", obj.getPersonalEmail());
		} else {
            st.setObject("personal_email", null);
}
if (obj.getAddress() != null) {
			st.setObject("address", obj.getAddress());
		} else {
            st.setObject("address", null);
}
if (obj.getBirthdateFrom() != null) {
			st.setObject("birthdateFrom", obj.getBirthdateFrom());
		} else {
			st.setObject("birthdateFrom", null);
		}
		if (obj.getBirthdateTo() != null) {
			st.setObject("birthdateTo", obj.getBirthdateTo());
		} else {
            st.setObject("birthdateTo", null);
}
if (obj.getIdentityNo() != null) {
			st.setObject("identity_no", obj.getIdentityNo());
		} else {
            st.setObject("identity_no", null);
}
		if (obj.getGenderSet()) {
			st.setObject("gender", obj.getGender());
		} else {
            st.setObject("gender", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
            st.setObject("description", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
            st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
            st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
            st.setObject("notification", null);
}
if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
            st.setObject("createdTo", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
            st.setObject("creator", null);
}
if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
            st.setObject("updatedTo", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
            st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
            st.setObject("deleted", null);
}
if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
            st.setObject("deletion_timeTo", null);
}
if (obj.getMiddleName() != null) {
			st.setObject("middle_name", obj.getMiddleName());
		} else {
            st.setObject("middle_name", null);
}
if (obj.getIdEmployee() != Integer.MIN_VALUE) {
			st.setObject("id_employee", obj.getIdEmployee());
		} else {
            st.setObject("id_employee", null);
}

	
		return st.getPreparedStatement();
	}

/*
	private String fillHtmlTemplate(String template) {
		String html = template
				.replace(":id", Integer.toString(_id))
.replace(":is_employee", HtmlUtil.genHtml(_isis_employeeSet, _is_employee))
.replace(":first_name", HtmlUtil.genHtml(_first_name))
.replace(":last_name", HtmlUtil.genHtml(_last_name))
.replace(":mobile", HtmlUtil.genHtml(_mobile))
.replace(":company_phone", HtmlUtil.genHtml(_company_phone))
.replace(":home_phone", HtmlUtil.genHtml(_home_phone))
.replace(":company_email", HtmlUtil.genHtml(_company_email))
.replace(":personal_email", HtmlUtil.genHtml(_personal_email))
.replace(":address", HtmlUtil.genHtml(_address))
.replace(":birthdate", StringUtil.toDateTimeString(_birthdate))
.replace(":identity_no", HtmlUtil.genHtml(_identity_no))
.replace(":gender", HtmlUtil.genHtml(_isgenderSet, _gender))
.replace(":description", HtmlUtil.genHtml(_description))
.replace(":status", Integer.toString(_status))
.replace(":is_draft", HtmlUtil.genHtml(_isis_draftSet, _is_draft))
.replace(":notification", Integer.toString(_notification))
.replace(":created", StringUtil.toDateTimeString(_created))
.replace(":creator", Integer.toString(_creator))
.replace(":updated", StringUtil.toDateTimeString(_updated))
.replace(":updator", Integer.toString(_updator))
.replace(":deleted", HtmlUtil.genHtml(_isdeletedSet, _deleted))
.replace(":deletion_time", StringUtil.toDateTimeString(_deletion_time))
.replace(":middle_name", HtmlUtil.genHtml(_middle_name))
.replace(":id_employee", Integer.toString(_id_employee))

				;
		return html;
	}
*/

/*
	private String fillHtmlTemplate(String template) {
		String html = template
				.replace(":Id", Integer.toString(_Id))
.replace(":IsEmployee", HtmlUtil.genHtml(_isIsEmployeeSet, _IsEmployee))
.replace(":FirstName", HtmlUtil.genHtml(_FirstName))
.replace(":LastName", HtmlUtil.genHtml(_LastName))
.replace(":Mobile", HtmlUtil.genHtml(_Mobile))
.replace(":CompanyPhone", HtmlUtil.genHtml(_CompanyPhone))
.replace(":HomePhone", HtmlUtil.genHtml(_HomePhone))
.replace(":CompanyEmail", HtmlUtil.genHtml(_CompanyEmail))
.replace(":PersonalEmail", HtmlUtil.genHtml(_PersonalEmail))
.replace(":Address", HtmlUtil.genHtml(_Address))
.replace(":Birthdate", StringUtil.toDateTimeString(_Birthdate))
.replace(":IdentityNo", HtmlUtil.genHtml(_IdentityNo))
.replace(":Gender", HtmlUtil.genHtml(_isGenderSet, _Gender))
.replace(":Description", HtmlUtil.genHtml(_Description))
.replace(":Status", Integer.toString(_Status))
.replace(":IsDraft", HtmlUtil.genHtml(_isIsDraftSet, _IsDraft))
.replace(":Notification", Integer.toString(_Notification))
.replace(":Created", StringUtil.toDateTimeString(_Created))
.replace(":Creator", Integer.toString(_Creator))
.replace(":Updated", StringUtil.toDateTimeString(_Updated))
.replace(":Updator", Integer.toString(_Updator))
.replace(":Deleted", HtmlUtil.genHtml(_isDeletedSet, _Deleted))
.replace(":DeletionTime", StringUtil.toDateTimeString(_DeletionTime))
.replace(":MiddleName", HtmlUtil.genHtml(_MiddleName))
.replace(":IdEmployee", Integer.toString(_IdEmployee))

				;
		return html;
	}
*/

}